#pragma once

#include <OgreArchive.h>
#include <OgreArchiveFactory.h>

namespace QuakeSandbox{

	/** Class for reading from Quake .pak files */
	class PakArchive : public Ogre::Archive
	{
	public:
		PakArchive( const Ogre::String& name, const Ogre::String& archType );
		virtual ~PakArchive();

		virtual bool isCaseSensitive(void) const;	  

		virtual void load();

		virtual void unload();

		virtual Ogre::DataStreamPtr open(const Ogre::String& filename) const;

		virtual Ogre::StringVectorPtr list(bool recursive = true, bool dirs = false);	   

		virtual Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);	   

		virtual Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true,
			bool dirs = false);	    

		virtual bool exists(const Ogre::String& filename);

		bool exists(const Ogre::String& filename) const;
	    
		virtual Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern, 
					 bool recursive = true, bool dirs = false);

	private:
		struct PackHandle;
		Ogre::SharedPtr<PackHandle> mPack;

		bool existsImpl(const Ogre::String& filename) const;

	};

	/** Specialisation of ArchiveFactory for Quake PAK files. */
	class PakArchiveFactory : public Ogre::ArchiveFactory
	{
	public:
		PakArchiveFactory(){}
		virtual ~PakArchiveFactory() {}
		
		const Ogre::String& getType(void) const;
		
		Ogre::Archive *createInstance( const Ogre::String& name ) 
		{
			return new PakArchive(name, "Pak");
		}
		
		void destroyInstance( Ogre::Archive* arch) { delete arch; }
	private:
		PakArchiveFactory(const PakArchiveFactory&);
		PakArchiveFactory operator=(const PakArchiveFactory&);
	};



}